<%@LANGUAGE="JAVASCRIPT" CODEPAGE="65001"%>
<!-- #include file = "core.asp" -->
<%
	var _system = $('system');
	var _database = $('database');
	_database.path = "database/#database.mdb";
	var _current = parseInt(_system.read('page')) || 1;
	
	var _list = _database.query('[Id], [Title], [Datetime]', '[Article]', '[CategoryId] = 16', '[Id] desc', 0, _current, 12);
	
	for (var _index in _list) {
		_list[_index].datetime = _system.format('date', _list[_index].datetime, 'YYYY-MM-DD');
	}
	
	
	var _queryString = _system.query;
	var _page = '';
	
	if (_queryString == '' || _queryString.indexOf('page') == 0) {
		_page = '<a href="?' + _queryString.replace(/page=\d+/gi, '') + 'page=1">首页</a>&nbsp;&nbsp;<a href="?' + _queryString.replace(/page=\d+/gi, '') + 'page=' + (_current - 1 > 0 ? _current - 1 : 1) + '">上一页</a>&nbsp;&nbsp;<a href="?' + _queryString.replace(/page=\d+/gi, '') + 'page=' + (_current + 1 < _database.pageCount ? _current + 1 : _database.pageCount) + '">下一页</a>&nbsp;&nbsp;<a href="?' + _queryString.replace(/page=\d+/gi, '') + 'page=' + _database.pageCount + '">尾页</a>&nbsp;&nbsp'
		_page += '第<select onchange="javascript:location=this.options[this.selectedIndex].value;">';
		for (var _index = 1; _index <= _database.pageCount; _index++) {
			_page += '<option value="?' + _queryString.replace(/page=\d+/gi, '') + 'page=' + _index + '"';
			if (_index == _current) {
				_page += 'selected="selected"';
			}
			_page += '>' + _index + '</option>';
		}
        _page += '</select>页';
		_page += '&nbsp;&nbsp;共' + _database.pageCount + '页';
	}
	else {
		_page = '<a href="?' + _queryString.replace(/&page=\d+/gi, '') + '&page=1">首页</a>&nbsp;&nbsp;<a href="?' + _queryString.replace(/&page=\d+/gi, '') + '&page=' + (_current - 1 > 0 ? _current - 1 : 1) + '">上一页</a>&nbsp;&nbsp;<a href="?' + _queryString.replace(/&page=\d+/gi, '') + '&page=' + (_current + 1 < _database.pageCount ? _current + 1 : _database.pageCount) + '">下一页</a>&nbsp;&nbsp;<a href="?' + _queryString.replace(/&page=\d+/gi, '') + '&page=' + _database.pageCount + '">尾页</a>&nbsp;&nbsp';
		_page += '第<select onchange="javascript:location=this.options[this.selectedIndex].value;">';
		for (var _index = 1; _index <= _database.pageCount; _index++) {
			_page += '<option value="?' + _queryString.replace(/&page=\d+/gi, '') + '&page=' + _index + '"';
			if (_index == _current) {
				_page += 'selected="selected"';
			}
			_page += '>' + _index + '</option>';
		}
        _page += '</select>页';
		_page += '&nbsp;&nbsp;共' + _database.pageCount + '页';
	}

	var _data = {
		list : _list,
		page : _page
	}
	
	var _template = $('template');
	_system.write(_template.render(_data));
%>
